# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.
#
# Contributor: xgdgsc <xgdgsc @t gmail dot com>

_android=android-14
_sdk=android-sdk
pkgname=android-sdk-build-tools
pkgver=r34
pkgrel=1
pkgdesc='Build-Tools for Google Android SDK (aapt, aidl, dexdump, dx, llvm-rs-cc).'
arch=('x86_64' 'aarch64')
url='https://developer.android.com/studio/releases/build-tools'
license=('custom:unknown')
depends=('zlib')
conflicts=('dioxus-cli')
source=("https://dl-ssl.google.com/android/repository/build-tools_$pkgver-linux.zip")
sha512sums=('c28dd52f8eca82996726905617f3cb4b0f0aee1334417b450d296991d7112cab1288f5fd42c48a079ba6788218079f81caa3e3e9108e4a6f27163a1eb7f32bd7')
options=('!strip')

package() {
  cd $pkgdir

  ver="$(cat "$srcdir/$_android/source.properties" |
  grep ^Pkg.Revision=|sed 's/Pkg.Revision=\([0-9.]*\).*/\1/')"

  install -dm 755 "opt/$_sdk/build-tools/$ver"
  install -dm 755 "usr/bin"
  install -Dm 644 "$srcdir/$_android/NOTICE.txt" \
    "usr/share/licenses/$pkgname/NOTICE.txt"
  cp -r "$srcdir/$_android/"* "opt/$_sdk/build-tools/$ver"
  chmod +Xr -R "$pkgdir/opt/$_sdk/build-tools/$ver"

  binaries=("aapt" "aapt2" "aidl" "apksigner" "bcc_compat" "d8" "dexdump" "dx" \
    "llvm-rs-cc" "mainDexClasses" "split-select" "zipalign")

  for f in "${binaries[@]}"; do
    ln -s "/opt/$_sdk/build-tools/$ver/$f" "usr/bin/$f"
  done
}

